package com.colin.app.activity.view.custom;


import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;

import com.colin.app.R;
import com.colin.app.activity.view.ViewContract;
import com.colin.app.activity.view.ViewPresenterImpl;
import com.colin.app.app.AppActivity;
import com.colin.app.bean.DemoBean;
import com.colin.library.view.FloatView;
import com.colin.library.view.custom.CustomViewCanvas;
import com.colin.library.view.custom.CustomViewOnDraw;

public class CustomViewActivity extends AppActivity implements ViewContract.ViewView {
    private ViewContract.ViewPresenter mViewPresenter = null;
    private FrameLayout frame_custom_view;
    private CustomViewOnDraw custom_view_draw;
    private CustomViewCanvas custom_view_canvas;
    private FloatView float_view ;
    @Override
    protected void onDestroy() {
        if (null!=mViewPresenter){
            mViewPresenter.destroy();
            mViewPresenter = null;
        }
        super.onDestroy();
    }

    @Override
    public void initPresenter() {
        DemoBean demoBean = getIntent().getExtras().getParcelable("clazz");
        mViewPresenter = new ViewPresenterImpl(this, this, demoBean);
    }

    @Override
    public int initViewLayoutID() {
        return R.layout.activity_custom_view;
    }

    @Override
    public void initView() {
        this.frame_custom_view = (FrameLayout) this.findViewById(R.id.frame_custom_view);
        this.custom_view_draw = (CustomViewOnDraw) this.findViewById(R.id.custom_view_draw);
        this.custom_view_canvas = (CustomViewCanvas) this.findViewById(R.id.custom_view_canvas);
        this.float_view = (FloatView) this.findViewById(R.id.float_view);
    }

    @Override
    public void initData() {
        mViewPresenter.setData();
    }

    @Override
    public void initListener() {
        this.float_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!float_view.isOpen()){
                    float_view.changeState();
                }
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_custom_view, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        switch (item.getItemId()) {
            case R.id.custom_view_draw:
                frame_custom_view.bringChildToFront(custom_view_draw);
                break;
            case R.id.custom_view_canvas:
                frame_custom_view.bringChildToFront(custom_view_canvas);
                break;
        }
        item.setChecked(true);
        return super.onOptionsItemSelected(item);
    }
}
